const Koa = require('koa')
const app = new Koa()
const Router = require('koa-router');
const views = require('koa-views');
const static = require('koa-static');
const path = require('path');
const router = new Router()
const bodyParser = require('koa-bodyparser')


app.use(bodyParser())
app.use(views(path.join(__dirname, './view'), {
  extension: 'ejs'
}));
app.use(static(
  path.join(__dirname, './public')
));
app.use(async (ctx, next) => {
  try {
    await next()
  } catch (err) {
    console.log(err);
    ctx.body = {
      code: -1,
      data: ctx.data,
      message: ctx.msg || err.message || '服务开小差了，请稍后再试',
      etime: Date.now(),
    }
  }
})

app.use(router.routes())
app.use(router.allowedMethods());








router.get('/xxx', async (ctx, next) => {

})






let server = app.listen(80, function () {
  console.log('服务启动，http://localhost:80');
})